
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/software.dart';

class SoftwareRepository {
  final SupabaseClient _client;

  SoftwareRepository(this._client);

  Future<List<Software>> getSoftwareList({int? categoryId}) async {
    var query = _client.from('software').select();
    
    if (categoryId != null) {
      query = query.eq('category_id', categoryId);
    }

    final response = await query.order('created_at', ascending: false);
    return response.map((json) => Software.fromJson(json)).toList();
  }

  Future<Software> getSoftwareById(int id) async {
    final response = await _client
        .from('software')
        .select()
        .eq('id', id)
        .single();
    return Software.fromJson(response);
  }
} 